package com.xinchuang.utils;

import com.xinchuang.entity.repacigi.RepacigiMainTable;
import com.xinchuang.entity.repacigi.RepacigiSubTable;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.impl.jam.provider.ResourcePath;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;

import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author meidan
 * @version 1.00
 * @className 昆明
 * @description <pre></pre>
 * @date 2023.9.19 20:19
 * @修改记录 <pre>
 *     版本          修改人         修改日期        修改描述
 *     ---------------------------------------------------
 *     1.00         Red       2023.9.19 20:19
 *     ---------------------------------------------------
 * </pre>
 */
public class WordUtils {

    public static void addPage(XWPFDocument doc, int index) throws Exception {
        // 复制索引之后的所有段落到新的文档中
        List<XWPFParagraph> newParagraphs = new ArrayList<>();
        for (int i = index; i < doc.getParagraphs().size(); i++) {
            newParagraphs.add(doc.getParagraphs().get(i));
        }
        XWPFDocument newDoc = new XWPFDocument();
        for (XWPFParagraph para : newParagraphs) {
            newDoc.createParagraph().createRun().setText(para.getText());
        }
        // 在新文档中插入一页
        newDoc.createParagraph().createRun().addBreak();
        // 将复制的段落再粘贴回原来的文档中
        for (XWPFParagraph para : newParagraphs) {
            doc.createParagraph().createRun().setText(para.getText());
        }
    }

    public static void copyTableByLoop2(String srcPath, int srcTableIndex, int copyNum, String storePath) throws Exception {
        InputStream is = new FileInputStream(new File(srcPath));
        XWPFDocument doc = new XWPFDocument(is);
        XWPFTable sourceTable = doc.getTableArray(srcTableIndex);
        int i = 10;
        for (int j = 0; j < copyNum; j++) {
            XWPFParagraph paragraph = doc.getParagraphs().get(i++);
            doc.insertNewParagraph(paragraph.getCTP().newCursor());
            insertTableInPara(sourceTable, doc, paragraph, false);
        }
        OutputStream os = Files.newOutputStream(Paths.get(storePath));
        doc.write(os);
        close(os);
        close(is);

    }

    public static void setTableValue(String storePath, List<RepacigiSubTable> repacigiSubTables) throws IOException {
        File file = new File(storePath);
        InputStream is = Files.newInputStream(file.toPath());
        XWPFDocument doc = new XWPFDocument(is);
        List<XWPFTable> tables = doc.getTables();
        for (int i = 1; i <= repacigiSubTables.size(); i++) {
            XWPFTable table = tables.get(i + 1);
            RepacigiSubTable repacigiSubTable = repacigiSubTables.get(i - 1);
            XWPFTableRow row1 = table.getRows().get(1);
            row1.getCell(row1.getTableCells().size() - 1).setText(repacigiSubTable.getSubName());
            XWPFTableRow row2 = table.getRows().get(2);
            row2.getCell(row2.getTableCells().size() - 1).setText(repacigiSubTable.getSubType());
            XWPFTableRow row3 = table.getRows().get(3);
            row3.getCell(row3.getTableCells().size() - 1).setText(repacigiSubTable.getLon());
            XWPFTableRow row4 = table.getRows().get(4);
            row4.getCell(row4.getTableCells().size() - 1).setText(repacigiSubTable.getLat());
            XWPFTableRow row5 = table.getRows().get(5);
            row5.getCell(row5.getTableCells().size() - 1).setText(repacigiSubTable.getGeoHeight());
            XWPFTableRow row6 = table.getRows().get(6);
            row6.getCell(row6.getTableCells().size() - 1).setText(repacigiSubTable.getAltitude());
            XWPFTableRow row7 = table.getRows().get(7);
            row7.getCell(row7.getTableCells().size() - 1).setText(repacigiSubTable.getPointError());
            XWPFTableRow row8 = table.getRows().get(8);
            row8.getCell(row8.getTableCells().size() - 1).setText(repacigiSubTable.getLatError());
            XWPFTableRow row9 = table.getRows().get(9);
            row9.getCell(row9.getTableCells().size() - 1).setText(repacigiSubTable.getLonError());
            XWPFTableRow row10 = table.getRows().get(10);
            row10.getCell(row10.getTableCells().size() - 1).setText(repacigiSubTable.getGeoHeightError());
            XWPFTableRow row11 = table.getRows().get(11);
            row11.getCell(row11.getTableCells().size() - 1).setText(repacigiSubTable.getAltitudeError());
            XWPFTableRow row12 = table.getRows().get(12);
            row12.getCell(row12.getTableCells().size() - 1).setText(repacigiSubTable.getMasterMapError());
            XWPFTableRow row13 = table.getRows().get(13);
            row13.getCell(row13.getTableCells().size() - 1).setText(repacigiSubTable.getArea());
            XWPFTableRow row14 = table.getRows().get(14);
            row14.getCell(row14.getTableCells().size() - 1).setText(repacigiSubTable.getStructureType());
            XWPFTableRow row15 = table.getRows().get(15);
            row15.getCell(row15.getTableCells().size() - 1).setText(null);
            XWPFTableRow row16 = table.getRows().get(16);
            row16.getCell(row16.getTableCells().size() - 1).setText(repacigiSubTable.getInRadius());
            XWPFTableRow row17 = table.getRows().get(17);
            row17.getCell(row17.getTableCells().size() - 1).setText(repacigiSubTable.getOutRadius());
            XWPFTableRow row18 = table.getRows().get(18);
            row18.getCell(row18.getTableCells().size() - 1).setText(repacigiSubTable.getLength());
            XWPFTableRow row19 = table.getRows().get(19);
            row19.getCell(row19.getTableCells().size() - 1).setText(repacigiSubTable.getWide());
            XWPFTableRow row20 = table.getRows().get(20);
            row20.getCell(row20.getTableCells().size() - 1).setText(repacigiSubTable.getAzimuthAngle());
        }
        OutputStream os = Files.newOutputStream(Paths.get(storePath));
        doc.write(os);
        close(os);
        close(is);
    }

    /**
     * <b> 循环复制Word中的表格
     * </b><br><br><i>Description</i> :
     *
     * @param srcPath 模板路径, srcTableIndex 模板中复制目标表格的下标, copyNum 复制个数, storePath 存储路径(包含文件名全称)
     * @return void
     * <br><br>Date: 2019/12/9 13:21     <br>Author : dxl
     */
    public static void copyTableByLoop(String srcPath, int srcTableIndex, int copyNum, String storePath) throws Exception {
        File file = new File(srcPath);
        InputStream is = Files.newInputStream(file.toPath());
        XWPFDocument doc = new XWPFDocument(is);
        XWPFTable sourceTable = doc.getTableArray(srcTableIndex);
        for (int j = 0; j < copyNum; j++) {
            XWPFTable tableOne = doc.createTable();
            for (int i = 0; i < sourceTable.getRows().size(); i++) {
                copy(tableOne, sourceTable.getRow(i), i);
            }
            doc.createParagraph();
            tableOne.removeRow(tableOne.getRows().size() - 1);
        }
        OutputStream os = Files.newOutputStream(Paths.get(storePath));
        XWPFDocument osDoc = new XWPFDocument(is);
        List<XWPFParagraph> paragraphs = osDoc.getParagraphs();
        insertTableInPara(sourceTable, osDoc, paragraphs.get(2), false);
        doc.write(os);
        close(os);
        close(is);

    }

    /**
     * 替换段落里面的变量
     *
     * @param para   要替换的段落
     * @param params 参数
     */
    private static void replaceInPara(XWPFParagraph para, Map<String, Object> params, XWPFDocument doc) {
        List<XWPFRun> runs;
        Matcher matcher;
        if (matcher(para.getParagraphText()).find()) {
            runs = para.getRuns();
            int start = -1;
            int end = -1;
            String str = "";
            for (int i = 0; i < runs.size(); i++) {
                XWPFRun run = runs.get(i);
                String runText = run.toString();
                if ((runText.length() > 0 && runText.contains("${"))
                        || (runText.length() > 0 && '$' == runText.charAt(runText.length() - 1) && i + 1 < runs.size() && '$' == runs.get(i + 1).toString().charAt(0))) {
                    start = i;
                }
                if (runText.length() > 0 && runText.contains("}")) {
                    if (start != -1) {
                        end = i;
                        break;
                    }
                }
            }
            for (int i = start; i <= end; i++) {
                str = str + runs.get(i).toString();
            }
            //去掉标识符开始之后到结束的run,保留第一个run是为了使用run的样式
            for (int i = start + 1; i <= end; i++) {
                para.removeRun(i);
                i--;
                end--;
            }
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                String key = entry.getKey();
                if (str.indexOf(key) != -1) {
                    Object value = entry.getValue();
                    if (value instanceof String) {
                        str = str.replace(key, value.toString());
                        para.getRuns().get(start).setText(str, 0);//替换保留的第一个run中的内容，若没有0就变为插入了
                        break;
                    } else if (value instanceof Map) {
                        str = str.replace(key, "");
                        Map pic = (Map) value;
                        int width = Integer.parseInt(pic.get("width").toString());
                        int height = Integer.parseInt(pic.get("height").toString());
                        int picType = getPictureType(pic.get("type").toString());
                        byte[] byteArray = (byte[]) pic.get("content");
                        ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray);
                        try {
                            doc.addPictureData(byteInputStream, picType);
                            break;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        if (matcher(para.getParagraphText()).find()) {
            replaceInPara(para, params, doc);
        }
    }

    /**
     * 为表格插入数据，行数不够添加新行
     * 说明：当表格中出现一行中每一个单元格都为'#'时，认为需要循环插入
     *
     * @param tableList 插入数据集合
     */
    private static void insertTable(XWPFTable table, List<String[]> tableList, boolean isMergeRow, List<List<Integer>> mergeRowLists) {
        int headRowNum = 0;
        int tailRowNum = 0;
        List<XWPFTableRow> rows = table.getRows();
        List<Integer> cellOrder = new ArrayList<>();
        for (int i = 0; i < rows.size(); i++) {
            String flagHead = "";
            String flagFor = "";
            for (int j = 0; j < rows.get(i).getTableCells().size(); j++) {
                String cellText = rows.get(i).getTableCells().get(j).getText().replace(" ", "");
                if (cellText.length() > 0) {
                    if (cellText.contains("#")) {
                        flagHead = flagHead + "#";
                    }
                    if (cellText.contains("#[") && cellText.contains("]") && cellText.indexOf("]") > cellText.indexOf("[") + 1
                            && cellOrder.size() < rows.get(i).getTableCells().size()) {
                        cellOrder.add(Integer.valueOf(cellText.substring(cellText.indexOf("[") + 1, cellText.indexOf("]"))));
                    } else if (cellText.contains("#") && cellOrder.size() < rows.get(i).getTableCells().size()) {
                        cellOrder.add(null);
                    }
                }
                //删除循环单元格内要替换段落后的多余run
                if (rows.get(i).getTableCells().get(j).getParagraphs().size() > 0) {
                    for (XWPFParagraph paragraph : rows.get(i).getTableCells().get(j).getParagraphs()) {
                        if (paragraph.getText().indexOf("#") == 0) {
                            for (int k = paragraph.getRuns().size() - 1; k > 0; k--) {
                                paragraph.removeRun(k);
                            }
                        }
                    }
                }
                flagFor = flagFor + "#";
            }
            if (flagFor.equals(flagHead)) {
                headRowNum = i;
                break;
            }
        }
        if (headRowNum > 0) {
            tailRowNum = rows.size() - headRowNum - 1;
            //创建行,根据需要插入的数据添加新行，不处理表头
            for (int i = 0; i < tableList.size(); i++) {
                copy(table, table.getRow(headRowNum), headRowNum + 1 + i);
            }
            //遍历表格插入数据

            int length = table.getRows().size();
            for (int i = headRowNum; i < length - tailRowNum - 1; i++) {
                XWPFTableRow newRow = table.getRow(i);
                List<XWPFTableCell> cells = newRow.getTableCells();
                for (int j = 0; j < cells.size(); j++) {
                    XWPFTableCell cell = cells.get(j);
                    String s = "";
                    if (j < tableList.get(i - headRowNum).length) {
                        if (cellOrder.get(j) != null && !cellOrder.get(j).equals(-1)) {
                            s = tableList.get(i - headRowNum)[cellOrder.get(j)];
                        } else if (cellOrder.get(j) != null && cellOrder.get(j).equals(-1)) {
                            s = "";
                        } else {
                            s = tableList.get(i - headRowNum)[j];
                        }
                    } else if (cellOrder.get(j) != null && !cellOrder.get(j).equals(-1)) {
                        s = tableList.get(i - headRowNum)[cellOrder.get(j)];
                    }
                    for (XWPFParagraph paragraph : cell.getParagraphs()) {
                        if (paragraph.getText().contains("#")) {
                            paragraph.getRuns().get(0).setText(s, 0);
                        }
                    }
                }
            }
            table.removeRow(table.getRows().size() - 1 - tailRowNum);
            if (isMergeRow && mergeRowLists.size() > 0) {
                for (List<Integer> listInts : mergeRowLists) {
                    mergeCellsRow(table, listInts.get(0), listInts.get(1), listInts.get(2));
                }
            }

        }
    }

    /**
     * 正则匹配字符串
     *
     * @param str
     * @return
     */
    private static Matcher matcher(String str) {
        Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher;
    }

    /**
     * 正则匹配字符串
     *
     * @param str
     * @return
     */
    private static Matcher matcherStar(String str) {
        Pattern pattern = Pattern.compile("\\*\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher;
    }

    /**
     * 根据图片类型，取得对应的图片类型代码
     *
     * @param picType
     * @return int
     */
    private static int getPictureType(String picType) {
        int res = XWPFDocument.PICTURE_TYPE_PICT;
        if (picType != null) {
            if (picType.equalsIgnoreCase("png")) {
                res = XWPFDocument.PICTURE_TYPE_PNG;
            } else if (picType.equalsIgnoreCase("dib")) {
                res = XWPFDocument.PICTURE_TYPE_DIB;
            } else if (picType.equalsIgnoreCase("emf")) {
                res = XWPFDocument.PICTURE_TYPE_EMF;
            } else if (picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")) {
                res = XWPFDocument.PICTURE_TYPE_JPEG;
            } else if (picType.equalsIgnoreCase("wmf")) {
                res = XWPFDocument.PICTURE_TYPE_WMF;
            }
        }
        return res;
    }


    /**
     * 关闭输入流
     *
     * @param is
     */
    private static void close(InputStream is) {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 关闭输出流
     *
     * @param os
     */
    private static void close(OutputStream os) {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * <b> 复制表格
     * </b><br><br><i>Description</i> :
     *
     * @param table, sourceRow, rowIndex
     * @return void
     * <br><br>Date: 2019/12/9 13:23     <br>Author : dxl
     */
    public static void copy(XWPFTable table, XWPFTableRow sourceRow, int rowIndex) {
        //在表格指定位置新增一行
        XWPFTableRow targetRow = table.insertNewTableRow(rowIndex);
        //复制行属性
        targetRow.getCtRow().setTrPr(sourceRow.getCtRow().getTrPr());
        List<XWPFTableCell> cellList = sourceRow.getTableCells();
        if (null == cellList) {
            return;
        }
        //复制列及其属性和内容
        XWPFTableCell targetCell = null;
        for (XWPFTableCell sourceCell : cellList) {
            targetCell = targetRow.addNewTableCell();
            //处理一个单元格内有多个段落
            List<XWPFParagraph> paragraphs = sourceCell.getParagraphs();
            if (paragraphs.size() > 1) {
                for (int i = 1; i < paragraphs.size(); i++) {
                    targetCell.addParagraph();
                }
            }
            //列属性
            targetCell.getCTTc().setTcPr(sourceCell.getCTTc().getTcPr());
            //段落属性
            if (sourceCell.getParagraphs() != null && sourceCell.getParagraphs().size() > 0) {
                for (int i = 0; i < sourceCell.getParagraphs().size(); i++) {
                    targetCell.getParagraphs().get(i).getCTP().setPPr(sourceCell.getParagraphs().get(i).getCTP().getPPr());
                    if (sourceCell.getParagraphs().get(i).getRuns() != null && sourceCell.getParagraphs().get(i).getRuns().size() > 0) {
                        for (int j = 0; j < sourceCell.getParagraphs().get(i).getRuns().size(); j++) {
                            XWPFRun cellR = targetCell.getParagraphs().get(i).createRun();
                            cellR.setText(sourceCell.getParagraphs().get(i).getRuns().get(j).getText(0));
                            cellR.setBold(sourceCell.getParagraphs().get(i).getRuns().get(j).isBold());
                            cellR.setColor(sourceCell.getParagraphs().get(i).getRuns().get(j).getColor());
                            if (sourceCell.getParagraphs().get(i).getRuns().get(j).getFontSize() == -1) {
                                cellR.setFontSize(10);
                            } else {
                                cellR.setFontSize(sourceCell.getParagraphs().get(i).getRuns().get(j).getFontSize());
                            }
                            cellR.setCapitalized(sourceCell.getParagraphs().get(i).getRuns().get(j).isCapitalized());
                            cellR.setDoubleStrikethrough(sourceCell.getParagraphs().get(i).getRuns().get(j).isDoubleStrikeThrough());
                            cellR.setEmbossed(sourceCell.getParagraphs().get(i).getRuns().get(j).isEmbossed());
                            cellR.setFontFamily(sourceCell.getParagraphs().get(i).getRuns().get(j).getFontFamily());
                            cellR.setImprinted(sourceCell.getParagraphs().get(i).getRuns().get(j).isImprinted());
                            cellR.setItalic(sourceCell.getParagraphs().get(i).getRuns().get(j).isItalic());
                            cellR.setKerning(sourceCell.getParagraphs().get(i).getRuns().get(j).getKerning());
                            cellR.setShadow(sourceCell.getParagraphs().get(i).getRuns().get(j).isShadowed());
                            cellR.setStrikeThrough(sourceCell.getParagraphs().get(i).getRuns().get(j).isStrikeThrough());
                            cellR.setSmallCaps(sourceCell.getParagraphs().get(i).getRuns().get(j).isSmallCaps());
                            cellR.setSubscript(sourceCell.getParagraphs().get(i).getRuns().get(j).getSubscript());
                            cellR.setTextPosition(sourceCell.getParagraphs().get(i).getRuns().get(j).getTextPosition());
                            cellR.setUnderline(sourceCell.getParagraphs().get(i).getRuns().get(j).getUnderline());
                        }
                    } else {
                        targetCell.setText(sourceCell.getText());
                    }
                }

            } else {
                targetCell.setText(sourceCell.getText());
            }
        }
    }

    /**
     * <b> 在段落中插入表格
     * </b><br><br><i>Description</i> : 表格单元格中建段落再插入表格，原段落会挤到下一个段落,用isDelNullPara控制删除空原段落，
     * isDelNullPara为true时要注意循环迭代，最好倒序循环para，插入表格后还有对para操作时也要注意，可能isDelNullPara要设为false
     *
     * @param sourceTable   要插入的源表格
     * @param targetDoc     要插入的文档
     * @param para          要插入表格的段落
     * @param isDelNullPara 是否删除para为空是多出来的空段落
     * @return void
     * <br><br>Date: 2019/12/12 11:39     <br>Author : dxl
     */
    public static void insertTableInPara(XWPFTable sourceTable, XWPFDocument targetDoc, XWPFParagraph para, boolean isDelNullPara) {
        XmlCursor cursor = para.getCTP().newCursor();
        XWPFTable tableOne = targetDoc.insertNewTbl(cursor);
        for (int i = 0; i < sourceTable.getRows().size(); i++) {
            copy(tableOne, sourceTable.getRow(i), i + 1);
        }
        if (isDelNullPara) {
            if (para.getText() != null && para.getText().length() > 0) {
            } else {
                targetDoc.removeBodyElement(targetDoc.getPosOfParagraph(para));
            }
        }
        tableOne.removeRow(0);
    }

    /**
     * @Description: 跨行合并
     */
    public static void mergeCellsRow(XWPFTable table, int col, int fromRow, int toRow) {
        for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
            XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
            if (rowIndex == fromRow) {
                // The first merged cell is set with RESTART merge value
                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
            } else {
                // Cells which join (merge) the first one, are set with CONTINUE
                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
            }
        }
    }

    public static void main(String[] args) {
        readWordTable("D:\\data\\newTarget\\file\\special\\bbb_成果报告_20231127211718.docx");
    }

    public static void readWordTable(String srcPath) {
        try {
            InputStream fis = new FileInputStream(new File(srcPath));
            XWPFDocument document = new XWPFDocument(fis);
            // 遍历所有段落和表格
            for (IBodyElement bodyElement : document.getBodyElements()) {
                if (bodyElement instanceof XWPFTable) {
                    if (bodyElement instanceof XWPFTable) {
                        // 如果元素是表格，则进一步处理
                        XWPFTable table = (XWPFTable) bodyElement;

                        // 获取表格的行数
                        int rows = table.getNumberOfRows();

                        // 遍历表格的所有行
                        for (int r = 0; r < rows; r++) {
                            XWPFTableRow row = table.getRow(r);

                            // 获取该行的单元格数量
                            int cells = row.getTableCells().size();

                            // 遍历每一列（单元格）
                            for (int c = 0; c < cells; c++) {
                                XWPFTableCell cell = row.getCell(c);

                                // 获取单元格的内容
                                String cellText = cell.getText();

                                System.out.println("Row " + (r+1) + ", Column " + (c+1) + ": " + cellText);

                                // 如果需要处理表格内的复杂内容，如图片、列表等，可以进一步深入解析
                            }
                        }
                    }
                }
            }
            // 关闭文档流
            document.close();
            fis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static RepacigiMainTable getMainTable(RepacigiMainTable mainTable, String name, String value) {
        switch (name) {
            case "国家地区":
                mainTable.setCountry(value);
                break;
            case "MB区":
                mainTable.setTarRegion(value);
                break;
            case "MB名称":
                mainTable.setTarName(value);
                break;
            case "MB编号":
                mainTable.setTarSerial(value);
                break;
            case "MB等级":
                mainTable.setTarGradient(value);
                break;
            case "MB类型":
                mainTable.setTarType(value);
                break;
            case "定位点子MB":
                mainTable.setSubPosition(value);
                break;
            case "坐标体系":
                mainTable.setCoordinateSystem(value);
                break;
            case "经度":
                mainTable.setLon(value);
                break;
            case "纬度":
                mainTable.setLat(value);
                break;
            case "大地高":
                mainTable.setGeoHeight(value);
                break;
            case "海拔高":
                mainTable.setAltitude(value);
                break;
            case "整编时间":
                mainTable.setReorganizeDate(value);
                break;
            case "整编单位":
                mainTable.setReorganizeUnit(value);
                break;
        }
        return mainTable;
    }

    public static RepacigiSubTable getSubTable(RepacigiSubTable subTable, String name, String value) {
        switch (name) {
            case "子MB名称":
                subTable.setSubName(value);
                break;
            case "子MB类型":
                subTable.setSubType(value);
                break;
            case "经度":
                subTable.setLon(value);
                break;
            case "纬度":
                subTable.setLat(value);
                break;
            case "大地高":
                subTable.setGeoHeight(value);
                break;
            case "海拔高":
                subTable.setAltitude(value);
                break;
            case "点位误差":
                subTable.setPointError(value);
                break;
            case "纬度误差":
                subTable.setLatError(value);
                break;
            case "经度误差":
                subTable.setLonError(value);
                break;
            case "大地高误差":
                subTable.setGeoHeightError(value);
                break;
            case "海拔误差":
                subTable.setAltitudeError(value);
                break;
            case "原图误差":
                subTable.setMasterMapError(value);
                break;
            case "面积":
                subTable.setArea(value);
                break;
            case "结构":
                subTable.setStructureType(value);
                break;
            case "子MB形状":
                subTable.setShapeType(value);
                break;
            case "圆内半径":
                subTable.setInRadius(value);
                break;
            case "圆外半径":
                subTable.setOutRadius(value);
                break;
            case "矩形长":
                subTable.setLength(value);
                break;
            case "矩形宽":
                subTable.setWide(value);
                break;
            case "矩形长方向夹角":
                subTable.setAzimuthAngle(value);
                break;
        }

        return subTable;
    }

}
